#include "Tools/ToolScaleObject.h"

using namespace Ogre;
ToolScaleObject::ToolScaleObject(Ogre::Camera *mCam, Ogre::SceneManager *mScMgr, RaySceneQuery* ray)
{
	objectSelected=false;
	altPressed=false;
	select = new ActionSelectObject(mCam,mScMgr,ray);
	moveCam = new ActionMoveCamera(mCam);
}

ToolScaleObject::~ToolScaleObject(){}

void ToolScaleObject::updateGraphics(const FrameEvent &evt){

	moveCam->updateGraphics(evt);
}

void ToolScaleObject::mouseMoved(const OIS::MouseEvent &evt){
	
	if(objectSelected)
		scale->mouseMoved(evt);
	moveCam->mouseMoved(evt);
}

void ToolScaleObject::mousePressed(const OIS::MouseEvent &evt){

	if(!objectSelected){
		if(select->mousePressed(evt)){
			scale = new ActionScaleObject(select->getSelectedNode());
			select->getSelectedNode()->showBoundingBox(true);
			objectSelected=true;
		}
	}
	else{
		select->getSelectedNode()->showBoundingBox(false);
		objectSelected=false;
		if(!altPressed)
			MapEditor::instance()->toolEnded();
	}	
}

void ToolScaleObject::keyPressed(const OIS::KeyEvent &evt){
	
	if(evt.key==OIS::KC_LMENU)
		altPressed=true;
	moveCam->keyPressed(evt);
}
void ToolScaleObject::keyReleased(const OIS::KeyEvent &e){

	if(e.key==OIS::KC_LMENU)
		altPressed=false;
	moveCam->keyReleased(e);
}
